<include file="Public/header" />
<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <h3>固件管理</h3>
      <ul class="tab-base">
        <li><a href="{:U('Firmware/firmware')}"><span>管理</span></a></li>
        <li><a href="JavaScript:void(0);" class="current"><span>编辑</span></a></li>
      </ul>
    </div>
  </div>
  <div class="fixed-empty"></div>
  <form id="goods_form" method="post" name="goods_form" enctype="multipart/form-data">
    <input name="id" type="hidden" value="{$rs['id']}"/>
    <table class="table tb-type2 nobdb">
      <tbody>


      <tr class="noborder">
        <td colspan="2" class="required"><label class="validation">所属版本:</label></td>
      </tr>
      <tr class="noborder">
        <td width="46" class="vatop rowform">
          <select name="class" id="class">
            <option value="驱动包" <if condition="$rs['class'] eq '驱动包'">selected="selected" </if>  >驱动包</option>
            <option value="BIOS和EC" <if condition="$rs['class'] eq 'BIOS和EC'">selected="selected" </if>  >BIOS和EC</option>
            <option value="显示驱动程序" <if condition="$rs['class'] eq '显示驱动程序'">selected="selected" </if>  >显示驱动程序</option>
            <option value="声卡驱动程序" <if condition="$rs['class'] eq '声卡驱动程序'">selected="selected" </if>  >声卡驱动程序</option>
            <option value="USB串行ATA驱动程序" <if condition="$rs['class'] eq 'USB串行ATA驱动程序'">selected="selected" </if>  >USB串行ATA驱动程序</option>
            <option value="芯片组" <if condition="$rs['class'] eq '芯片组'">selected="selected" </if>  >芯片组</option>
            <option value="WiFi驱动程序" <if condition="$rs['class'] eq 'WiFi驱动程序'">selected="selected" </if>  >WiFi驱动程序</option>
            <option value="网络驱动程序" <if condition="$rs['class'] eq '网络驱动程序'">selected="selected" </if>  >网络驱动程序</option>
            <option value="蓝牙驱动程序" <if condition="$rs['class'] eq '蓝牙驱动程序'">selected="selected" </if>  >蓝牙驱动程序</option>
            <option value="软件程序" <if condition="$rs['class'] eq '软件程序'">selected="selected" </if>  >软件程序</option>
            <option value="USB端口驱动" <if condition="$rs['class'] eq 'USB端口驱动'">selected="selected" </if>  >USB端口驱动</option>
            <option value="General Driver" <if condition="$rs['class'] eq 'General Driver'">selected="selected" </if>  >General Driver</option>
            <option value="其它驱动程序" <if condition="$rs['class'] eq '其它驱动程序'">selected="selected" </if>  >其它驱动程序</option>
            <option value="操作指南" <if condition="$rs['class'] eq '操作指南'">selected="selected" </if>  >操作指南</option>
            <option value="指纹驱动" <if condition="$rs['class'] eq '指纹驱动'">selected="selected" </if>  >指纹驱动</option>
            <option value="操作系统" <if condition="$rs['class'] eq '操作系统'">selected="selected" </if>  >操作系统</option>
            <option value="固件" <if condition="$rs['class'] eq '固件'">selected="selected" </if>  >固件</option>

          </select>
        </td>
        <td class="vatop tips"></td>
      </tr>


      <tr class="noborder">
        <td colspan="2" class="required"><label class="validation">所属版本:</label></td>
      </tr>
      <tr class="noborder">
        <td width="46" class="vatop rowform">
          <select name="ver" id="ver">
            <option value="cn" <if condition="$rs['ver'] eq 'cn'">selected="selected" </if>>中文(cn)</option>
            <option value="en" <if condition="$rs['ver'] eq 'en'">selected="selected" </if>>英文(en)</option>
          </select>
        </td>
        <td class="vatop tips"></td>
      </tr>


      <tr class="noborder">
        <td colspan="2" class="required"><label class="validation">固件名称:</label></td>
      </tr>
      <tr class="noborder">
        <td class="vatop rowform"><input type="text" value="{$rs['name']}" name="name" id="name" class="txt"></td>
        <td class="vatop tips"></td>
      </tr>

      <tr class="noborder">
        <td colspan="2" class="required"><label class="validation">固件描述:</label></td>
      </tr>
      <tr class="noborder">
        <td class="vatop rowform"><textarea id="describe" class="tarea" rows="3" name="describe">{$rs['describe']}</textarea></td>
        <td class="vatop tips"></td>
      </tr>


      <!--<tr class="noborder">
        <td colspan="2" class="required"><label class="validation">产品价格:</label></td>
      </tr>
      <tr class="noborder">
        <td class="vatop rowform">
        <input type="text" value="{$rs['goods_price']}" name="goods_store_price" id="goods_store_price" class="txt">
        </td>
        <td class="vatop tips"></td>
      </tr>-->

      <!--<tr class="noborder">
        <td colspan="2" class="required"><label>产品规格:</label></td>
      </tr>
      <tr class="noborder">
        <td colspan="15">
          <table class="table tb-type2">
            <thead id="spec_tt">
              <tr class="noborder">
                <th class="w48 sort">排序</th>
                <th class="w270 name">规格值</th>
                <th class="w270 price">价格</th>
                <th class="w150 align-center">操作</th>
                <th></th>
              </tr>
            </thead>
            <tbody id="tr_model">
              <tr></tr>
             <volist name="spec_list" id="sp">
              <tr class="hover edit">
              <td class="w48 sort"><input type="text" name="s_value[s_{$i}][sort]" value="{$sp['spec_goods_sort']}" /></td>
              <td class="w270 name"><input type="text" name="s_value[s_{$i}][name]" value="{$sp['spec_name']}" /></td>
              <td class="w270 price"><input type="text" data_type="price" name="s_value[s_{$i}][price]" value="{$sp['spec_goods_price']}" /></td>
              <td class="w150 align-center"><a onclick="remove_tr($(this));" href="JavaScript:void(0);">移除</a></td>
              <td></td>
              </tr>
            </volist>
            </tbody>
            <tbody>
              <tr>
                <td colspan="15"><a class="btn-add marginleft" id="add_type" href="JavaScript:void(0);" onclick="add_spec()"> <span>添加一个规格值</span> </a></td>
              </tr>
            </tbody>
          </table>
        </td>
      </tr>-->

      <!--        <tr class="noborder">
                <td colspan="2" class="required"><label class="validation">产品库存:</label></td>
              </tr>
              <tr class="noborder">
                <td class="vatop rowform"><input type="text" value="{$rs['goods_storage']}" name="goods_storage" id="goods_price" class="txt"></td>
                <td class="vatop tips"></td>
              </tr>
              <tr class="noborder">
                <td colspan="2" class="required"><label>产品货号:</label></td>
              </tr>
              <tr class="noborder">
                <td class="vatop rowform"><input type="text" value="{$rs['goods_serial']}" name="goods_serial" id="goods_serial" class="txt"></td>
                <td class="vatop tips"></td>
              </tr>   -->

      <tr>
        <td colspan="2" class="required"><label>下载文件:</label></td>
      </tr>
      <!--<tr class="noborder">
        <td class="vatop rowform">
            <span class="type-file-show">
          	{$rs['download']}
            &lt;!&ndash;<div class="type-file-preview"><img src="__UPLOADS__{$rs['goods_pic']}"></div>&ndash;&gt;
            </span>
          <span class="type-file-box">
            <input type='text' name='txt_goods_pic' id='txt_goods_pic' class='type-file-text' />
            <input type='button' name='but_goods_pic' id='but_goods_pic' value='' class='type-file-button' />
            <input name="download" type="file" class="type-file-file" id="goods_pic" size="30" hidefocus="true" nc_type="change_goods_pic">
            </span>
        </td>
        <td class="vatop tips"><span class="vatop rowform"></span></td>
      </tr>-->

      <tr class="noborder">
        <td class="vatop rowform"><textarea id="download" class="tarea" rows="3" name="download">{$rs['download']}</textarea></td>
        <td class="vatop tips"></td>
      </tr>


      </tbody>
      <tfoot>
      <tr class="tfoot">
        <td colspan="15" ><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span>保存</span></a></td>
      </tr>
      </tfoot>
    </table>
  </form>
</div>
<script type="text/javascript">
  $("#spec_tt").hide();
  var i=<?php echo $spec_list_i;?>;
  var tr_model = '<tr class="hover edit">'+
          '<td class="w48 sort"><input type="text" name="s_value[key][sort]" value="0" /></td>'+
          '<td class="w270 name"><input type="text" name="s_value[key][name]" value="" /></td>'+
          '<td class="w270 price"><input type="text" data_type="price" name="s_value[key][price]" value="" /></td>'+
          '<td class="w150 align-center"><a onclick="remove_tr($(this));" href="JavaScript:void(0);">移除</a></td>'+
          '<td></td>'+
          '</tr>';
  function add_spec()
  {
    $("#spec_tt").show();
    $('input[name="goods_store_price"]').attr('readonly','readonly').css('background','#E7E7E7 none');
    $('#tr_model > tr:last').after(tr_model.replace(/key/g,'s_'+i));
    $.getScript("__JS__/admincp.js");
    i++;
  }
  function remove_tr(o)
  {
    o.parents('tr:first').remove();
    var tr_num = $("#tr_model tr").size();
    update_price();
    if(tr_num == 1)
    {
      $('input[name="goods_store_price"]').attr('readonly','').css('background','');
    }
  }
  function update_price()
  {
    var max = 0.01;
    var min = 10000000;
    $('input[data_type="price"]').each(function(){
      if($(this).val() != '')
      {
        max = Math.max(max,$(this).val());
        min = Math.min(min,$(this).val());
        $('input[name="goods_store_price"]').val(min);
      }
      if($(this).val() == '')
      {
        $(this).val($('input[name="goods_store_price"]').val());
      }
    });
  }
  $(document).ready(function(){
    $('#submitBtn').click(function(){
      update_price();
    });
  });
</script>
<script>
  //按钮先执行验证再提交表单
  $(function(){$("#submitBtn").click(function(){
    if($("#goods_form").valid()){
      $("#goods_form").submit();
    }
  });
  });
  //
  $(document).ready(function(){
    $('#goods_form').validate({
      errorPlacement: function(error, element){
        error.appendTo(element.parent().parent().prev().find('td:first'));
      },
      success: function(label){
        label.addClass('valid');
      },
      rules : {
        gc_id : {
          required   : true
        },
        goods_name : {
          required   : true
        },
        goods_desc : {
          required : true
        },
        goods_store_price : {
          required   : true,
          number : true
        },
        /*			goods_storage:{
                        required   : true,
                        number : true
                    },*/
        goods_sort : {
          number : true
        },
        goods_body : {
          required   : true
        }
      },
      messages : {
        gc_id : {
          required   : '请选择分类'
        },
        goods_name : {
          required   : '请输入产品名称'
        },
        goods_desc : {
          required : '输入产品描述'
        },
        goods_store_price : {
          required   : '请输入产品价格',
          number : '产品价格输入错误'
        },
        /*			goods_storage : {
                        required   : '请输入产品库存',
                        number : '产品库存输入错误'
                    },*/
        goods_sort : {
          number : '排序格式输入错误'
        },
        goods_body : {
          required   : '请输入产品信息'
        }
      }
    });

  });
</script>
<script type="text/javascript">
  // 模拟网站LOGO上传input type='file'样式
  $(function(){
    $("#goods_pic").change(function(){
      $("#txt_goods_pic").val($(this).val());
    });
// 上传图片类型
    $('input[class="type-file-file"]').change(function(){
      var filepatd=$(this).val();
      var extStart=filepatd.lastIndexOf(".");
      var ext=filepatd.substring(extStart,filepatd.lengtd).toUpperCase();
      /*if(ext!=".PNG"&&ext!=".GIF"&&ext!=".JPG"&&ext!=".JPEG"){
        alert("图片格式错误");
        $(this).attr('value','');
        return false;
      }*/
    });
  });
</script>
<include file="Public/footer" />